package com.itjeffrey.autocode.postProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 后置处理器测试
 * InstantiationAwareBeanPostProcessor -> postProcessBeforeInstantiation，可以直接返回自己创建的bean，容器停止自动创建
 * @From: Jeffrey
 * @Date: 2021/3/27
 */
@Component
public class MyBeanPostProccessor implements InstantiationAwareBeanPostProcessor {

    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        if(beanClass == ADemo.class){
            ADemo aDemo = new ADemo();
            System.out.println(aDemo.toString());
            return aDemo;
        }
        return null;
    }
}
